package com.ror.java.se.reflect;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Demo04 {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Class<Student> stuClass = Student.class;
        Method toStringMtd = stuClass.getMethod("toString");
        Student stu1 = new Student("张三", 24, "男");
        String stuStr = (String) toStringMtd.invoke(stu1); //反射调用方法
        System.out.println(stuStr);
    }
}
